<?php

use Faker\Factory as Faker;
use App\Models\Channel;
use App\Repositories\ChannelRepository;

trait MakeChannelTrait
{
    /**
     * Create fake instance of Channel and save it in database
     *
     * @param array $channelFields
     * @return Channel
     */
    public function makeChannel($channelFields = [])
    {
        /** @var ChannelRepository $channelRepo */
        $channelRepo = App::make(ChannelRepository::class);
        $theme = $this->fakeChannelData($channelFields);
        return $channelRepo->create($theme);
    }

    /**
     * Get fake instance of Channel
     *
     * @param array $channelFields
     * @return Channel
     */
    public function fakeChannel($channelFields = [])
    {
        return new Channel($this->fakeChannelData($channelFields));
    }

    /**
     * Get fake data of Channel
     *
     * @param array $postFields
     * @return array
     */
    public function fakeChannelData($channelFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'name' => $fake->word,
            'type' => $fake->word,
            'country' => $fake->word,
            'state_id' => $fake->randomDigitNotNull,
            'state' => $fake->word,
            'state_name' => $fake->word,
            'county_id' => $fake->randomDigitNotNull,
            'county' => $fake->word,
            'county_name' => $fake->word,
            'zip_id' => $fake->randomDigitNotNull,
            'zip_code' => $fake->word,
            'zip' => $fake->word,
            'zip_name' => $fake->word,
            'address' => $fake->word,
            'linkman_name' => $fake->word,
            'linkman_phone' => $fake->word,
            'linkman_wechat' => $fake->word,
            'linkman_duty' => $fake->word,
            'status' => $fake->randomDigitNotNull,
            'updated_at' => $fake->word,
            'created_at' => $fake->word
        ], $channelFields);
    }
}
